import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
import '../model.dart';

class BannerSwiper extends StatelessWidget {
  final List<BannerItem> bannerList;
  final double height;
  final Function(int)? onTap;

  const BannerSwiper({
    super.key, 
    required this.bannerList,
    this.height = 200,
    this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    if (bannerList.isEmpty) {
      return SizedBox(height: height);
    }

    return SizedBox(
      height: height,
      child: Swiper(
        itemBuilder: (context, index) {
          return Container(
            margin: const EdgeInsets.symmetric(horizontal: 16),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(12),
              color: Colors.white,
            ),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(6),
              child: Image.network(
                bannerList[index].imgUrl,
                fit: BoxFit.cover,
                errorBuilder: (context, error, stackTrace) {
                  return Container(
                    color: Colors.grey[200],
                    child: const Icon(Icons.error),
                  );
                },
              ),
            ),
          );
        },
        itemCount: bannerList.length,
        pagination: SwiperPagination(
          alignment: Alignment.bottomCenter,
          builder: DotSwiperPaginationBuilder(
            color: Colors.white.withOpacity(0.5),
            activeColor: Colors.white,
            size: 6.0,
            activeSize: 7.0,
          ),
        ),
        autoplay: true,
        autoplayDelay: 3000,
        outer: false,
      ),
    );
  }
}
